<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../styles/common.css"/>
    <link rel="stylesheet" href="../../styles/page.css"/>
    <style>
        .container {
            height: 800px;
        }
    </style>
</head>
<body>
<div class="dashboard-container" id="statistics-app">
    <div class="container">
        <div>
            <div id="main" style="width: 600px;height:550px;float:left"></div>
            <div id="mainTwo" style="width: 600px;height:550px;float:right"></div>
        </div>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入 echarts.min.js -->
<script src="../../js/echarts.min.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/statistics.js"></script>
<script>
    new Vue({
        el: '#statistics-app',
        data() {
            return {
                chart: [],
                chartLine: [],
                tableData: [],
                tableUserData: {}
            }
        },
        computed: {},
        created() {
        },
        mounted() {
            this.init()
        },
        methods: {
            async init() {
                await getCateSta().then(res => {
                    if (res.code == '200') {
                        this.tableData = res.data || []
                        console.log(this.tableData)
                        this.chart = echarts.init(document.getElementById('main'))
                        this.chart.setOption({
                            title: {
                                text: '菜品 套餐的数量占比图',
                                subtext: '数据统计',
                                left: 'center'
                            },
                            tooltip: {
                                trigger: 'item'
                            },
                            legend: {
                                orient: 'vertical',
                                left: 'left'
                            },
                            series: [
                                {
                                    name: 'tableData',
                                    type: 'pie',
                                    radius: '50%',
                                    data: [...this.tableData],
                                    emphasis: {
                                        itemStyle: {
                                            shadowBlur: 8,
                                            shadowOffsetX: 3,
                                            shadowColor: 'rgba(1, 0, 0, 0.5)'
                                        }
                                    }
                                }
                            ]
                        });
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
                await getUserCount().then(res => {
                    if (res.code == "200") {
                        this.tableUserData = res.data || []
                        this.chartLine = echarts.init(document.getElementById('mainTwo'))
                        this.chartLine.setOption({
                            title: {
                                text: '用户增长折线图',
                                subtext: '数据统计',
                                left: 'left'
                            },
                            dataset: {
                                dimensions: ['ndate', 'counts'],
                                source: [
                                    ...this.tableUserData
                                ],
                            },
                            xAxis: {
                                type: 'category',
                                // data: []
                            },
                            yAxis: {
                                type: 'value'
                            },
                            series: [
                                {
                                    // data: [],
                                    type: 'line'
                                }
                            ]
                        })
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            }
        }
    })
</script>
</body>
</html>
